package com.lxt.basicmvc.utils;

import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.lxt.basicmvc.BuildConfig;
import com.lxt.basicmvc.base.C;
import com.orhanobut.logger.Logger;

/**
 * Created by GLX on 2017/5/8.
 */

public class L {

    public static boolean isDebug = BuildConfig.DEBUG;

//    public static void log(String title, String msg) {
//        if (isDebug) {
//            Log.e(title, msg);
//        }
//    }
//
//    public static void log(String msg) {
//        if (isDebug) {
//            Log.e("打印数值：", msg);
//        }
//
//    }
//
//    public static void d(String tag, String msg) {
//        if (isDebug) {
//            Log.d(tag, msg);
//        }
//    }
//
//    public static void i(String tag, String msg) {
//        if (isDebug) {
//            Log.i(tag, msg);
//        }
//    }
//
//    public static void w(String tag, String msg) {
//        if (isDebug) {
//            Log.w(tag, msg);
//        }
//    }
//
//    public static void e(String tag, String msg) {
//        if (isDebug) {
//            Log.e(tag, msg);
//        }
//    }

    public L() {
    }

    /**
     * Send a VERBOSE log message.
     *
     * @param msg The message you would like logged.
     */
    public static void v(String msg) {
        if (isDebug)
            Logger.v(msg);
    }

    /**
     * Send a DEBUG log message.
     *
     * @param msg The message you would like logged.
     */
    public static void d(String msg) {
        if (isDebug)
            Logger.d(msg);
    }

    /**
     * Send an INFO log message.
     *
     * @param msg The message you would like logged.
     */
    public static void i(String msg) {
        if (isDebug)
            Logger.i(msg);
    }

    /**
     * Send an ERROR log message.
     *
     * @param msg The message you would like logged.
     */
    public static void e(String msg) {
        if (isDebug)
            Logger.e(msg);
    }

    /**
     * Send a WARN log message
     *
     * @param msg The message you would like logged.
     */
    public static void w(String msg) {
        if (isDebug)
            Logger.w(msg);
    }

    //test use : print object
    public static void printObject(Object object){
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeSpecialFloatingPointValues();
        Gson gson = gsonBuilder.create();
        String result = gson.toJson(object);
        e("object json:"+result);
    }

    private static String buildMessage(String msg) {
        //通过StackTraceElement获取当前打印日志的类名和方法名，这个用来代替我们平时手写的TAG值。
        // StackTrace用栈的形式保存了方法的调用信息
        StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];

        return caller.getClassName() + "." + caller.getMethodName() + "(): " + msg;
    }


}
